package com.phpxiu.app.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.list.Language;

import java.util.List;

/**
 * Created by 吴金洲 on 2016/8/12
 */
public class LanguageListAdapter extends BaseAdapter<Language> {

    public LanguageListAdapter(Context context, List<Language> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Language language=data.get(position);
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.language_list_item_view,null);
        }
        TextView nameView=(TextView)convertView.findViewById(R.id.language_name);
        nameView.setText(language.getName());
        ImageView stateIcon=(ImageView)convertView.findViewById(R.id.check_state_icon);
        if(language.isSelected()){
            if(stateIcon.getVisibility()!=View.VISIBLE){
                stateIcon.setVisibility(View.VISIBLE);
            }
        }else{
            if(stateIcon.getVisibility()==View.VISIBLE){
                stateIcon.setVisibility(View.INVISIBLE);
            }
        }
        convertView.findViewById(R.id.item_divider).setVisibility(View.VISIBLE);
        if(data.size()>0&&position==data.size()-1){
            convertView.findViewById(R.id.item_divider).setVisibility(View.INVISIBLE);
        }
        convertView.setTag(language);
        return convertView;
    }
}
